<?php
/**
 * 推荐位模型
 * Created by Sublime Text 3.
 * @authors Rejeo (rejeo@qq.com)
 * @date    2018-05-03 13:35:05
 * @version $Id$
 */
namespace app\common\model;

use app\common\model\BaseModel;

class Featured extends BaseModel
{

    // 列表展示
    public function getFeaturedByType($type)
    {
        $data = [
            // 'type' => ['gt', -1],
            'status' => ['gt', -1],
        ];
        if (is_numeric($type)) {
           $data['type'] = intval($type);
        }

        $res = $this->where($data)->paginate();
        return $res;
    }

    // 获取首页大图和右边推荐位图
    public function getFeaturedImage($type=1)
    {
        $key = 'Featured_'.$type;
        if (cache($key)) {
            return cache($key);
        }
        $data = [
            'type' => $type,
            'status' => 1,
        ];
        $field = ['id','type','title','image','url','description','status'];
        $res = $this->where($data)->field($field)->limit(5)->select();
        // 数据缓存
        cache($key,$res,600);
        return $res;
    }
}
